<?php
require_once 'common/config.php';
require_once 'common/functions.php';

// 检查登录状态
check_login();

$db = db_connect();

// 获取预约ID
$booking_id = isset($_GET['id']) ? intval($_GET['id']) : 0;

// 获取预约详情
$sql = "SELECT b.*, c.name as coach_name, c.phone as coach_phone, c.email as coach_email,
        u.name as user_name, u.phone as user_phone, u.email as user_email, u.gender as user_gender,
        c.price as coach_price, c.description as coach_description
        FROM bookings b 
        LEFT JOIN users u ON b.user_id = u.id 
        LEFT JOIN coaches c ON b.coach_id = c.id 
        WHERE b.id = :booking_id AND b.type = 1";
$stmt = $db->prepare($sql);
$stmt->bindValue(':booking_id', $booking_id);
$stmt->execute();
$booking = $stmt->fetch(PDO::FETCH_ASSOC);

// 如果没有找到预约记录，重定向到列表页
if (!$booking) {
    header('Location: private_bookings.php');
    exit;
}

// 状态映射
$status_types = [
    0 => ['name' => '待确认', 'badge' => 'badge-warning'],
    1 => ['name' => '已确认', 'badge' => 'badge-info'],
    2 => ['name' => '已完成', 'badge' => 'badge-success'],
    3 => ['name' => '已取消', 'badge' => 'badge-danger']
];
?>

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>预约详情 - <?php echo SITE_NAME; ?></title>
    <link rel="stylesheet" href="assets/css/style.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
</head>
<body>
    <div class="wrapper">
        <?php include 'includes/sidebar.php'; ?>
        
        <div class="main-content">
            <header class="top-header">
                <div class="header-left">
                    <h2>预约详情</h2>
                </div>
                <div class="header-right">
                    <a href="private_bookings.php" class="btn btn-secondary">
                        <i class="fas fa-arrow-left"></i> 返回列表
                    </a>
                </div>
            </header>

            <div class="content">
                <!-- 预约基本信息 -->
                <div class="detail-card">
                    <h3>预约信息</h3>
                    <div class="info-group">
                        <div class="info-item">
                            <label>预约编号：</label>
                            <span><?php echo $booking['id']; ?></span>
                        </div>
                        <div class="info-item">
                            <label>预约日期：</label>
                            <span><?php echo $booking['booking_date']; ?></span>
                        </div>
                        <div class="info-item">
                            <label>时间段：</label>
                            <span><?php echo htmlspecialchars($booking['time_slot']); ?></span>
                        </div>
                        <div class="info-item">
                            <label>价格：</label>
                            <span>¥<?php echo number_format($booking['price'], 2); ?></span>
                        </div>
                        <div class="info-item">
                            <label>状态：</label>
                            <span class="badge <?php echo $status_types[$booking['status']]['badge']; ?>">
                                <?php echo $status_types[$booking['status']]['name']; ?>
                            </span>
                        </div>
                        <div class="info-item">
                            <label>创建时间：</label>
                            <span><?php echo date('Y-m-d H:i:s', strtotime($booking['created_at'])); ?></span>
                        </div>
                    </div>
                </div>

                <!-- 用户信息 -->
                <div class="detail-card">
                    <h3>用户信息</h3>
                    <div class="info-group">
                        <div class="info-item">
                            <label>姓名：</label>
                            <span><?php echo htmlspecialchars($booking['user_name']); ?></span>
                        </div>
                        <div class="info-item">
                            <label>手机号：</label>
                            <span><?php echo htmlspecialchars($booking['user_phone']); ?></span>
                        </div>
                        <div class="info-item">
                            <label>邮箱：</label>
                            <span><?php echo htmlspecialchars($booking['user_email']); ?></span>
                        </div>
                        <div class="info-item">
                            <label>性别：</label>
                            <span><?php echo $booking['user_gender'] == '1' ? '男' : '女'; ?></span>
                        </div>
                    </div>
                </div>

                <!-- 教练信息 -->
                <div class="detail-card">
                    <h3>教练信息</h3>
                    <div class="info-group">
                        <div class="info-item">
                            <label>姓名：</label>
                            <span><?php echo htmlspecialchars($booking['coach_name']); ?></span>
                        </div>
                        <div class="info-item">
                            <label>手机号：</label>
                            <span><?php echo htmlspecialchars($booking['coach_phone']); ?></span>
                        </div>
                        <div class="info-item">
                            <label>邮箱：</label>
                            <span><?php echo htmlspecialchars($booking['coach_email']); ?></span>
                        </div>
                        <div class="info-item">
                            <label>课时费：</label>
                            <span>¥<?php echo number_format($booking['coach_price'], 2); ?>/节</span>
                        </div>
                    </div>
                    <div class="info-item full-width">
                        <label>个人简介：</label>
                        <div class="description">
                            <?php echo nl2br(htmlspecialchars($booking['coach_description'])); ?>
                        </div>
                    </div>
                </div>

                <?php if ($booking['remark']): ?>
                <!-- 备注信息 -->
                <div class="detail-card">
                    <h3>备注信息</h3>
                    <div class="description">
                        <?php echo nl2br(htmlspecialchars($booking['remark'])); ?>
                    </div>
                </div>
                <?php endif; ?>
            </div>
        </div>
    </div>

    <style>
    .detail-card {
        background: #fff;
        border-radius: 8px;
        box-shadow: 0 2px 4px rgba(0,0,0,0.05);
        padding: 20px;
        margin-bottom: 20px;
    }

    .detail-card h3 {
        margin: 0 0 20px 0;
        color: #2c3e50;
        font-size: 18px;
        font-weight: 600;
    }

    .info-group {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
        gap: 20px;
    }

    .info-item {
        display: flex;
        align-items: baseline;
    }

    .info-item.full-width {
        grid-column: 1 / -1;
    }

    .info-item label {
        min-width: 80px;
        color: #666;
        font-weight: 500;
    }

    .info-item span {
        flex: 1;
        color: #333;
    }

    .description {
        margin-top: 10px;
        color: #666;
        line-height: 1.6;
    }

    .badge {
        padding: 6px 12px;
        border-radius: 4px;
        font-size: 12px;
        font-weight: 500;
    }

    .badge-warning {
        background: #fff3cd;
        color: #856404;
        border: 1px solid #ffeeba;
    }

    .badge-info {
        background: #d1ecf1;
        color: #0c5460;
        border: 1px solid #bee5eb;
    }

    .badge-success {
        background: #d4edda;
        color: #155724;
        border: 1px solid #c3e6cb;
    }

    .badge-danger {
        background: #f8d7da;
        color: #721c24;
        border: 1px solid #f5c6cb;
    }

    .btn-secondary {
        padding: 8px 16px;
        background: #6c757d;
        color: #fff;
        border: none;
        border-radius: 4px;
        text-decoration: none;
        transition: background 0.3s;
    }

    .btn-secondary:hover {
        background: #5a6268;
    }

    .header-right {
        margin-left: auto;
    }
    </style>
</body>
</html> 